<%@ page import="java.util.ArrayList" %>
<%@ page import="com.xiaolin.bean.Shopp" %>
<%@ page import="com.xiaolin.utils.dbUtils" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="com.xiaolin.dao.impl.AllShoppDAOImol" %>
<%@ page import="java.util.List" %>
<%@ page import="com.xiaolin.dao.impl.BookShoppDAOImpl" %>
<%@ page import="com.xiaolin.dao.impl.ComputerDAOImol" %>
<%@ page import="com.xiaolin.dao.impl.DigitalDAOImpl" %>
<%@ page import="java.text.DecimalFormat" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2023/1/6
  Time: 19:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>展示商品</title>
    <link type="text/css" rel="stylesheet" href="../css/ShoppShown.css">
    <script type="text/javascript" src="script/jquery-1.7.2.js"></script>

</head>
<body>
<%
    int num = Integer.parseInt(request.getParameter("num"));
    List<Shopp> list = new ArrayList<>();
    Connection conn = dbUtils.getConnection();
    if (num == 1) {
        AllShoppDAOImol imol = new AllShoppDAOImol();
        list = imol.getAll(conn);
    } else if (num == 2) {
        BookShoppDAOImpl imol = new BookShoppDAOImpl();
        list = imol.getAll(conn);
    } else if (num == 3) {
        ComputerDAOImol imol = new ComputerDAOImol();
        list = imol.getAll(conn);
    } else if (num == 4) {
        DigitalDAOImpl imol = new DigitalDAOImpl();
        list = imol.getAll(conn);
    }
    for (int i = 0; i < list.size(); i++) {
        Shopp shopp = list.get(i);
        DecimalFormat decimalFormat = new DecimalFormat(".00");
        String format = decimalFormat.format(shopp.getPrice());
%>
<script type="text/javascript">
    $(function () {
        $("#l<%=i%>").click(function () {
            var text = $("#s<%=i%>");
            var p = text.text();
            if (p != 1) {
                text.text(p - 1);
            }
            var f = $("#f<%=i%>");
            var url = "eveShopp.jsp?num=" + text.text() + "&id=<%=shopp.getId()%>&a=<%=num%>&name=<%=request.getParameter("name")%>"
            f.attr("action", url)
        })
        $("#r<%=i%>").click(function () {
            var text = $("#s<%=i%>");
            var p = Number(text.text());
            if (p != 0) {
                text.text(p+1);
            }
            var f = $("#f<%=i%>");
            var url = "eveShopp.jsp?num=" + text.text() + "&id=<%=shopp.getId()%>&a=<%=num%>&name=<%=request.getParameter("name")%>"
            f.attr("action", url)
        })
    })
</script>
<div class="div1">
    <div class="div2">
        <img src="<%=shopp.getImg()%>.png">
    </div>
    <div class="div4">
        <b><%=shopp.getName()%>
        </b>
    </div>
    <div class="div5">
        <div class="div6">￥<%=format%>
        </div>
        <div class="div6">
            <button id="l<%=i%>" class="b1">-</button>
            <span id="s<%=i%>">1</span>
            <button id="r<%=i%>" class="b2">-</button>
        </div>
        <form id="f<%=i%>" action="eveShopp.jsp?num=1&a=<%=num%>&id=<%=shopp.getId()%>&name=<%=request.getParameter("name")%>" method="post" class="div6">
            <input type="submit" value="加入购物车">
        </form>
    </div>
</div>
<%
    }
%>
</body>
</html>
